package com.lq.gulimall.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.lq.gulimall.product.service.PmsAttrGroupService;
import com.lq.gulimall.product.vo.Attr;
import com.lq.gulimall.product.vo.AttrReadVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lq.gulimall.product.entity.PmsAttrEntity;
import com.lq.gulimall.product.service.PmsAttrService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 商品属性
 *
 * @author lq
 * @email 
 * @date 2020-11-09 19:28:37
 */
@RestController
@RequestMapping("product/attr")
public class PmsAttrController {
    @Autowired
    private PmsAttrService pmsAttrService;
    @Autowired
    private PmsAttrGroupService pmsAttrGroupService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = pmsAttrService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**     sale/list
     * 列表
     */
    @RequestMapping("/{attrType}/list/{catId}")
    public R basElist(@RequestParam Map<String, Object> params,@PathVariable("catId")Long catId,
                       @PathVariable("attrType")String type){
        PageUtils page=  pmsAttrService.queryPage(params,catId,type);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    public R info(@PathVariable("attrId") Long attrId){
		//PmsAttrEntity pmsAttr = pmsAttrService.getById(attrId);
        AttrReadVo attrReadVo= pmsAttrService.getAttrInfo(attrId);
        return R.ok().put("attr", attrReadVo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody Attr attr){
		pmsAttrService.saveAttr(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrReadVo pmsAttr){
		pmsAttrService.updateAttr(pmsAttr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrIds){
		pmsAttrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
